package com.um.jdy.platform.month.controller;

import com.um.jdy.platform.month.entity.dto.CardOrderExportDTO;
import com.um.jdy.platform.month.entity.dto.CardOrderPageDTO;
import com.um.jdy.platform.month.entity.dto.CardOrderRefundDTO;
import com.um.jdy.platform.month.entity.vo.CardOrderItemVO;
import com.um.jdy.platform.month.manager.CardOrderManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ExportParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 控制器：用户月卡订单
 */
@RestController
@RequestMapping("/api/v1/cms/month/card_order")
@Api(tags = "用户月卡订单", description = "CardOrderController")
@ApiPermission("card_order")
@Validated
@TokenRequired
public class CardOrderController extends BaseController<CardOrderManager> {

    /**
     * 分页查询月卡订单
     *
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询月卡订单")
    @PostMapping("page")
    public Response<Page<CardOrderItemVO>> getPage(@RequestBody CardOrderPageDTO params) {
        return manager.getPage(params.toPageParams());
    }

    /**
     * 月卡退款
     *
     * @return
     */
    @ApiPermission("refund")
    @ApiOperation("月卡退款")
    @PostMapping("refund")
    public Response refund(@Valid  @RequestBody CardOrderRefundDTO params) {
        return manager.refund(params);
    }

    /**
     * 导出充电订单
     *
     * @param params
     * @return
     */
    @ApiPermission("export")
    @ApiOperation("导出订单")
    @PostMapping("/export_order_page")
    public Response exportOrderPage(@RequestBody CardOrderExportDTO params) {
        ExportParams exportParams = params.toExportParams(
                new String[]{"deviceStationId","orderNo", "outTradeNo", "nickname","mobile"},
                new String[]{"o.device_station_id","o.order_no", "o.out_trade_no", "u.nickname","u.mobile"},
                "o.create_time","beginTime","endTime");
        return manager.exportOrderPage(exportParams);
    }

}
